import History from './base';
export default class BrowserHistory extends History {
  constructor (router) {
    super (router);
  }
  getCurrentLocation () {
    return window.location.pathname;
  }
  setupListener () {
    // 监听前进后退
    window.addEventListener ('popstate', () => {
      this.transitionTo (this.getCurrentLocation ());
    });
  }

  // 跳转到新路径
  push (location) {
    // 先跳转更新视图，然后修改路径， 顺序不重要
    this.transitionTo (location, () => {
      window.history.pushState ({}, null, location);
    });
    // window.location.pathname = location;
  }
}
